package org.jeecg.modules.friends.base;

import java.util.Map;

import org.springframework.core.env.Environment;

import com.google.common.collect.Maps;

import cn.hutool.core.net.NetUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.system.SystemUtil;

/**
 * Created on 2023-05-18
 */
public class ServerTool {

    private static Map<String, String> serverMap = Maps.newHashMap();

    static {

        serverMap.put("172.21.39.49", "gradeSchool");
        serverMap.put("172.21.39.51", "adjust");
        serverMap.put("172.21.39.45", "common");
    }

    private static boolean isPort(String port) {
        return port.equals(SpringUtil.getBean(Environment.class).getProperty("server.port"));
    }

    // 是linux系统的 && 必须是指定端口才能执行
    public static boolean isCommonServerPort(String port) {
        return SystemUtil.getOsInfo().isLinux() && isPort(port) && "172.21.39.45".equals(NetUtil.getLocalhostStr());
    }

    public static boolean isGradeSchoolServer() {
        return "172.21.39.49".equals(NetUtil.getLocalhostStr());
    }

    public static boolean isAdjustServer() {
        return "172.21.39.51".equals(NetUtil.getLocalhostStr());
    }

    public static boolean isCommonServer() {
        return "172.21.39.45".equals(NetUtil.getLocalhostStr());
    }

    public static String getServerName() {
        return serverMap.getOrDefault(NetUtil.getLocalhostStr(), "");
    }
}
